﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Avatar.ResumeService;
using System.Web.Security;
using AvatarHelper;
using Avatar.Model;
using System.Data.Linq;
using Avatar.Common;
using Avatar.MembershipService;

public partial class PersonJobIntention : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
            try
            {
                ResumeManager.PersonResumeBasicInformationCheck(LoginManager.GetCurrentUser().UserName);
            }
            catch (Exception)
            {
                Helper.ShowMassage("个人基本资料未填写，请先填写个人基本资料。", "PersonInformation.aspx");
            }

        if (!IsPostBack)
        {
            var _user = LoginManager.GetCurrentUser();
            if (_user != null)
            {
                using (var _adc = DBHelper.GetDataContext())
                {
                    DropDownListHelper.Bind(ddl_JobType, _adc.JobType.ToList(), "name", "ID");
                    DropDownListHelper.Bind(ddl_ExpectationMoney, _adc.ExpectationMoney.ToList(), "name", "ID");
                    DropDownListHelper.Bind(ddl_TimeOnDuty, _adc.TimeOnDuty.ToList(), "name", "ID");
                    DropDownListHelper.Bind(ddl_Attutide, _adc.Attitude.ToList(), "JobAttitude", "ID");
                    DropDownListHelper.Bind(ddl_Position, _adc.Position.Where(p => p.FatherID == 0).ToList(), "name", "ID");

                    var _resume = _adc.Resume.Where(r => r.User == _user.UserName).FirstOrDefault();
                    if (_resume != null)
                    {
                        if (_resume.JobIntention != null)
                        {
                            ddl_JobType.SelectedValue = _resume.JobIntention.JobTypeID.ToString();
                            List<int> _indu = new List<int>();
                            foreach (var _i in _resume.JobIntention.JobIntentionIndustry)
                            {
                                _indu.Add(_i.IndustryID);
                            }
                            Industry1.Select = _indu;
                            List<int> _po = new List<int>();
                            foreach (var _i in _resume.JobIntention.JobIntentionPosition)
                            {
                                _po.Add(_i.PositionID);
                            }
                            //PositionII1.Select = _po;
                            ddl_ExpectationMoney.SelectedValue = _resume.JobIntention.ExpectationMoney.ToString();
                            ddl_TimeOnDuty.SelectedValue = _resume.JobIntention.TimeOnDutyID.ToString();
                            ddl_Attutide.SelectedValue = _resume.JobIntention.AttitudeID.ToString();
                            Location1.City = _resume.JobIntention.AreaID;
                        }
                    }
                }
            }
        }
    }
    protected void btn_Submit_Click(object sender, EventArgs e)
    {
        try
        {
            JobIntentionManager.SaveJobIntention(
                LoginManager.GetCurrentUser().UserName,
                Location1.City,
                Convert.ToInt32(ddl_ExpectationMoney.SelectedValue),
                Industry1.Select,
                Convert.ToInt32(ddl_JobType.SelectedValue),
                Convert.ToInt32(ddl_Position.SelectedValue),
                txt_PositionName.Text,
                Convert.ToInt32(ddl_Attutide.SelectedValue),
                Convert.ToInt32(ddl_TimeOnDuty.SelectedValue)
                );

            Response.Redirect("./PersonResume.aspx");
        }
        catch (Exception _e)
        {
            lbl_Error.Text = _e.Message;
        }
    }
}
